{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "current_time = datetime.now()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2017, 4, 22, 19, 35, 38, 697981)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "current_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(current_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2017-04-22'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "current_time.strftime('%Y-%m-%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2017, 4, 22, 0, 0)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = '2017/04-22'\n",
    "datetime.strptime(s, '%Y/%m-%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from datetime import timedelta\n",
    "newday = current_time - timedelta(days = 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.timedelta(10)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "current_time - newday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2017, 5, 2, 19, 35, 38, 697981)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " current_time + timedelta(days = 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2017/04/21\n",
      "2017/04/20\n",
      "2017/04/19\n",
      "2017/04/18\n",
      "2017/04/17\n",
      "2017/04/16\n",
      "2017/04/15\n",
      "2017/04/14\n",
      "2017/04/13\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    #print(i)\n",
    "    dt = current_time - timedelta(days = i)\n",
    "    print(dt.strftime('%Y/%m/%d'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1492860938.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from time import mktime\n",
    "mktime(current_time.timetuple())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2017, 4, 22, 19, 35, 38)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.fromtimestamp(1492860938)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>标题</th>\n",
       "      <th>建筑面积</th>\n",
       "      <th>总价</th>\n",
       "      <th>户型</th>\n",
       "      <th>朝向</th>\n",
       "      <th>物 业 费</th>\n",
       "      <th>环比上月</th>\n",
       "      <th>张贴日期</th>\n",
       "      <th>产权性质</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>资深经纪上海人：稀缺3房，南北通透采光好，房东急需用钱！</td>\n",
       "      <td>123.50</td>\n",
       "      <td>760</td>\n",
       "      <td>3室2厅0厨2卫</td>\n",
       "      <td>南北</td>\n",
       "      <td>1.5元/平米・月</td>\n",
       "      <td>↑1.44%</td>\n",
       "      <td>西元2017年4月12日</td>\n",
       "      <td>商品房</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>未来规划小上海，精装带地暖，养老，亲子，旅游度假一体化</td>\n",
       "      <td>86.00</td>\n",
       "      <td>76</td>\n",
       "      <td>2室2厅1厨1卫</td>\n",
       "      <td>南北</td>\n",
       "      <td>1.8元/・月</td>\n",
       "      <td>↑4.08%</td>\n",
       "      <td>西元2017年4月13日</td>\n",
       "      <td>商品房</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>双高铁 不限贷 买一层送一层 送大露台 看房专车接送</td>\n",
       "      <td>90.00</td>\n",
       "      <td>80</td>\n",
       "      <td>3室2厅1厨2卫</td>\n",
       "      <td>南北</td>\n",
       "      <td>暂无资料</td>\n",
       "      <td>↓0.01%</td>\n",
       "      <td>西元2017年4月14日</td>\n",
       "      <td>商品房</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>坐拥嘉兴海宁双轨 享受市区配套 现房值得拥有 可落户</td>\n",
       "      <td>90.00</td>\n",
       "      <td>80</td>\n",
       "      <td>2室1厅1厨1卫</td>\n",
       "      <td>南北</td>\n",
       "      <td>暂无资料</td>\n",
       "      <td>↓0.01%</td>\n",
       "      <td>西元2017年4月15日</td>\n",
       "      <td>商品房</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>对口明强校区，精装两房税费少，位置安静，媲美园艺新村，随时看</td>\n",
       "      <td>66.61</td>\n",
       "      <td>285</td>\n",
       "      <td>2室1厅1厨1卫</td>\n",
       "      <td>南</td>\n",
       "      <td>0.8元/平米・月</td>\n",
       "      <td>↓2.62%</td>\n",
       "      <td>西元2017年4月16日</td>\n",
       "      <td>个人产权</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               标题    建筑面积   总价        户型  朝向      物 业 费  \\\n",
       "0    资深经纪上海人：稀缺3房，南北通透采光好，房东急需用钱！  123.50  760  3室2厅0厨2卫  南北  1.5元/平米・月   \n",
       "1     未来规划小上海，精装带地暖，养老，亲子，旅游度假一体化   86.00   76  2室2厅1厨1卫  南北    1.8元/・月   \n",
       "2      双高铁 不限贷 买一层送一层 送大露台 看房专车接送   90.00   80  3室2厅1厨2卫  南北       暂无资料   \n",
       "3      坐拥嘉兴海宁双轨 享受市区配套 现房值得拥有 可落户   90.00   80  2室1厅1厨1卫  南北       暂无资料   \n",
       "4  对口明强校区，精装两房税费少，位置安静，媲美园艺新村，随时看   66.61  285  2室1厅1厨1卫   南  0.8元/平米・月   \n",
       "\n",
       "     环比上月          张贴日期  产权性质  \n",
       "0  ↑1.44%  西元2017年4月12日   商品房  \n",
       "1  ↑4.08%  西元2017年4月13日   商品房  \n",
       "2  ↓0.01%  西元2017年4月14日   商品房  \n",
       "3  ↓0.01%  西元2017年4月15日   商品房  \n",
       "4  ↓2.62%  西元2017年4月16日  个人产权  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas\n",
    "df = pandas.read_excel('data/house_sample.xlsx')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 29 entries, 0 to 29\n",
      "Data columns (total 9 columns):\n",
      "标题       29 non-null object\n",
      "建筑面积     29 non-null float64\n",
      "总价       29 non-null int64\n",
      "户型       29 non-null object\n",
      "朝向       29 non-null object\n",
      "物 业 费    29 non-null object\n",
      "环比上月     29 non-null object\n",
      "张贴日期     29 non-null object\n",
      "产权性质     29 non-null object\n",
      "dtypes: float64(1), int64(1), object(7)\n",
      "memory usage: 2.3+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "df['张贴日期'] = pandas.to_datetime(df['张贴日期'], format = '西元%Y年%m月%d日')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 29 entries, 0 to 29\n",
      "Data columns (total 9 columns):\n",
      "标题       29 non-null object\n",
      "建筑面积     29 non-null float64\n",
      "总价       29 non-null int64\n",
      "户型       29 non-null object\n",
      "朝向       29 non-null object\n",
      "物 业 费    29 non-null object\n",
      "环比上月     29 non-null object\n",
      "张贴日期     29 non-null datetime64[ns]\n",
      "产权性质     29 non-null object\n",
      "dtypes: datetime64[ns](1), float64(1), int64(1), object(6)\n",
      "memory usage: 2.3+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "?pandas.read_csv"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
